/**
 * @param {number[][]} matrix
 * @return {number[]}
 */
var spiralOrder = function (matrix) {
	//  判断矩阵是否为空
	if (!matrix.length || !matrix[0].length) {
		// matrix.length获取行数，matrix[0].length获取列数
		return [];
	}
	// 定义行列数
	const rows = matrix.length, columns = matrix[0].length;
	const res = [];
	let left = 0, right = columns - 1, top = 0, bottom = rows - 1;
	while (left <= right && top <= bottom) {
		// 从左到右
		for (let i = left; i <= right; i++) {
			res.push(matrix[top][i]);
		}
		// 从上到下
		for (let i = top + 1; i <= bottom; i++) {
			res.push(matrix[i][right]);
		}
		if (left < right && top < bottom) {
			// 从右到左
			for (let i = right - 1; i > left; i--) {
				res.push(matrix[bottom][i]);
			}
			// 从下到上
			for (let i = bottom; i > top ; i--) {
				res.push(matrix[i][left])
			}
		}
		// 改变要打印的一圈值的边界
		[left, right, top, bottom] = [left + 1, right - 1, top + 1, bottom - 1];
	}
	return res;
};
let matrix = [[3],[2]];
console.log(spiralOrder(matrix));